import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/grouppurchase',
    // children: [{
    //   path: 'dashboard',
    //   name: 'Dashboard',
    //   component: () => import('@/views/dashboard/index'),
    //   meta: { title: 'Dashboard', icon: 'dashboard' }
    // }]
  },
  {
    path: '/buyer',
    component: Layout,
    redirect: '/buyer/purchaseInfoRelease',
    name: 'Buyer',
    meta: { title: '我是买方', icon: 'shopcar' },
    children: [
      {
        path: 'purchaseInfoRelease',
        name: 'purchaseInfoRelease',
        component: () => import('@/views/buyer/purchaseInfoRelease/index'),
        meta: { title: '采购信息发布' }
      },
      {
        path: 'purchaseInfoManagement',
        name: 'purchaseInfoManagement',
        component: () => import('@/views/buyer/purchaseInfoManagement/index'),
        meta: { title: '采购信息管理' }
      },
      {
        path: 'purchaseOrderManagement',
        name: 'purchaseOrderManagement',
        component: () => import('@/views/buyer/purchaseOrderManagement/index'),
        meta: { title: '采购订单管理' }
      }
    ]
  },
  {
    path: '/seller',
    component: Layout,
    redirect: '/seller/saleInfoRelease',
    name: 'Seller',
    meta: { title: '我是卖方', icon: 'seller' },
    children: [
      {
        path: 'saleInfoRelease',
        name: 'saleInfoRelease',
        component: () => import('@/views/seller/saleInfoRelease/index'),
        meta: { title: '销售信息发布' }
      },
      {
        path: 'saleInfoManagement',
        name: 'saleInfoManagement',
        component: () => import('@/views/seller/saleInfoManagement/index'),
        meta: { title: '销售信息管理' }
      },
      {
        path: 'saleOrderManagement',
        name: 'saleOrderManagement',
        component: () => import('@/views/seller/saleOrderManagement/index'),
        meta: { title: '销售订单管理' }
      }
    ]
  },
  {
    path: '/grouppurchase',
    component: Layout,
    redirect: '/grouppurchase/groupPurchaseManagement',
    name: 'Grouppurchase',
    meta: { title: '集采业务', icon: 'grouppurchase' },
    children: [
      {
        path: 'groupPurchaseManagement',
        name: 'groupPurchaseManagement',
        component: () => import('@/views/grouppurchase/groupPurchaseManagement/index'),
        meta: { title: '团购业务管理' }
      },
      {
        path: 'groupSaleManagement',
        name: 'groupSaleManagement',
        component: () => import('@/views/grouppurchase/groupSaleManagement/index'),
        meta: { title: '集中销售管理' }
      },
      {
        path: 'groupBuyManagement',
        name: 'groupBuyManagement',
        component: () => import('@/views/grouppurchase/groupBuyManagement/index'),
        meta: { title: '集中购销管理' }
      }
    ]
  },

  {
    path: '/myaccount',
    component: Layout,
    redirect: '/myaccount/modifyPassword',
    name: 'myaccount',
    meta: { title: '我的账户', icon: 'myaccount' },
    children: [
      {
        path: 'modifyPassword',
        name: 'modifyPassword',
        component: () => import('@/views/myaccount/modifyPassword/index'),
        meta: { title: '修改密码' }
      },
      
    ]
  },
  {
    path: '/stock',
    component: Layout,
    redirect: '/stock/inStorageManagement',
    name: 'stock',
    meta: { title: '库存管理', icon: 'stock' },
    children: [
      {
        path: 'inStorageManagement',
        name: 'inStorageManagement',
        component: () => import('@/views/stock/inStorageManagement/index'),
        meta: { title: '入库管理' }
      },
      {
        path: 'outStorageManagement',
        name: 'outStorageManagement',
        component: () => import('@/views/stock/outStorageManagement/index'),
        meta: { title: '出库管理' }
      },
      {
        path: 'myStock',
        name: 'myStock',
        component: () => import('@/views/stock/myStock/index'),
        meta: { title: '我的库存' }
      },
    ]
  },
  {
    path: '/stockorder',
    component: Layout,
    redirect: '/stockorder/stockOrderRegister',
    name: 'stockorder',
    meta: { title: '仓单管理', icon: 'stockorder' },
    children: [
      {
        path: 'stockOrderRegister',
        name: 'stockOrderRegister',
        component: () => import('@/views/stockorder/stockOrderRegister/index'),
        meta: { title: '仓单注册' }
      },
      {
        path: 'stockOrderCancel',
        name: 'stockOrderCancel',
        component: () => import('@/views/stockorder/stockOrderCancel/index'),
        meta: { title: '仓单注销' }
      },
      {
        path: 'myStockOrder',
        name: 'myStockOrder',
        component: () => import('@/views/stockorder/myStockOrder/index'),
        meta: { title: '我的仓单' }
      },
    ]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
